package com.neusoft.ch9.objectdemo;

public class Student {
	private String stuName;
	private String stuNo;
	private String stuSex;

	public Student(String stuName, String stuNo, String stuSex) {
		super();
		this.stuName = stuName;
		this.stuNo = stuNo;
		this.stuSex = stuSex;
	}

	public String getStuName() {
		return stuName;
	}

	public void setStuName(String stuName) {
		this.stuName = stuName;
	}

	public String getStuNo() {
		return stuNo;
	}

	public void setStuNo(String stuNo) {
		this.stuNo = stuNo;
	}

	public String getStuSex() {
		return stuSex;
	}

	public void setStuSex(String stuSex) {
		this.stuSex = stuSex;
	}

	@Override
	public boolean equals(Object obj) {
		// 判定学生内容是否相同
		// 如果 == 为true，则内容肯定相同
		if (this == obj) {
			return true;
		}
		// 如果 obj是Student类型
		if (obj instanceof Student) {
			// 向下溯型（把父类类型重新转换为子类类型）
			Student anotherStu = (Student) obj;
			// 根据业务需求判定学生内容是否相同
			// 业务要求：姓名相同、学号相同、性别相同，则内容相同
			if (this.getStuName().equals(anotherStu.getStuName()) && this.getStuNo().equals(anotherStu.getStuNo())
					&& this.getStuSex().equals(anotherStu.getStuSex())) {
				// 学生内容相同
				return true;
			}
		}
		return false;
	}

	@Override
	public String toString() {
		// 可以自定义格式
		return "Student [stuName=" + stuName + ", stuNo=" + stuNo + ", stuSex=" + stuSex + "]";
	}

}
